<template>
    <div class="particulars">
        <v-detail :detailData="inputData" :inputConfig="inputConfig" :rules="rules" @pop="setdata"
                  ref="input"></v-detail>
    </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
    name: "particulars",
    mixins: [baseMixin],
    props: {
        inputData: {
            type: Object
        }
    },
    data() {
        return {
            inputConfig: [
                [
                    {
                        type: "input",
                        label: this.$t('config.taskReason'),
                        props: "taskmanagerreasonkey",
                        disabled: !this.$store.state.newFlag
                    },
                    {
                        type: "textarea",
                        label: this.$t('common.desc'),
                        props: "descr",
                    },
                    {
                        type: "select",
                        label: this.$t('in.lpn') + this.$t('config.freezeCode'),
                        props: "idholdkey",
                        options: this.getOptions('codelkup/holdCode')
                    },
                    {
                        type: "select",
                        label: this.$t('config.docyclecount'),
                        props: "docyclecount",
                        options: this.getOptions('codelkup/YESNO')
                    },
                ],
                [
                    {
                        type: "select",
                        label: this.$t('config.removeTaskFromUserQueue'),
                        props: "removetaskfromuserqueue",
                        options: this.getOptions('codelkup/YESNO')
                    },
                    {
                        type: "select",
                        label: this.$t('config.taskStatus'),
                        props: "taskstatus",
                        options: this.getOptions('codelkup/TMSTATUS')
                    },
                    {
                        type: "table",
                        label: this.$t('config.toLoc'),
                        props: "toloc",
                        tableConfig: [
                            {
                                label: this.$t('config.loc'),
                                prop: "loc",
                                input: "input",
                            },
                            {
                                label: this.$t('common.type'),
                                prop: "locationtype",
                                input: "select",
                                options: this.getOptions('querycodeLkup/LOCTYPE')
                            },
                            {
                                label: this.$t('config.area'),
                                prop: "putawayzone",
                                input: "select",
                                options: this.getOptions('queryPutawayzoneDropDown')
                            },
                            {
                                label: this.$t('config.locFlag'),
                                prop: "locationflag",
                                input: "select",
                                options: this.getOptions('querycodeLkup/LOCFLAG')
                            },
                            {
                                label: this.$t('config.locCategory'),
                                prop: "locationcategory",
                                input: "select",
                                options: this.getOptions('querycodeLkup/LOCCATEGRY')
                            },
                            {
                                label: this.$t('config.loseId'),
                                prop: "loseid",
                                input: "select",
                                options: this.getOptions('querycodeLkup/YESNO')
                            },
                            {
                                label: this.$t('config.commingleLot'),
                                prop: "comminglelot",
                                input: "select",
                                options: this.getOptions('querycodeLkup/YESNO')
                            },
                            {
                                label: this.$t('config.commingleSku'),
                                prop: "comminglesku",
                                input: "select",
                                options: this.getOptions('querycodeLkup/YESNO')
                            },
                            {
                                label: this.$t('config.capacity'),
                                prop: "cubiccapacity",
                                input: "input",
                            },
                        ],
                        url: "/queryLoc/"
                    },
                    {
                        type: "select",
                        label: this.$t('config.locFreezeCode'),
                        props: "locholdkey",
                        options: this.getOptions('codelkup/holdCode')
                    },
                ],
                [
                    {
                        type: "select",
                        label: this.$t('config.continueProcessing'),
                        props: "continueprocessing",
                        options: this.getOptions('codelkup/YESNO')
                    },
                    {
                        type: "input",
                        label: this.$t('config.interval'),
                        props: "interval",
                    },
                    {
                        type: "select",
                        label: this.$t('config.reAllocateOrder'),
                        props: "reallocateorder",
                        options: this.getOptions('codelkup/YESNO')
                    },
                ]
            ],
            rules: {
                taskmanagerreasonkey: [
                    {required: true, validator: this.taskmanagerreasonkey, trigger: 'blur'},
                ],
                toloc: [
                    {validator: this.toloc, trigger: 'blur'},
                ],
                interval: [
                    {required: true, validator: this.interval, trigger: 'blur'},
                ]
            },
        }
    },
    computed: {},
    methods: {
        taskmanagerreasonkey(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                var re = /^[^\u4e00-\u9fa5]{0,}$/;
                let te = value;
                let flag = re.test(te)
                if (flag) {
                    callback();
                } else {
                    this.$message.error(this.$tj('config.taskReason','app.dataIsNotZh'));
                    this.inputData[rule.field] = ""
                    callback(new Error());
                }
            }
        },
        toloc(rule, value, callback) {
            if (value != '') {
                // callback(new Error());
                this.$api.get(`/queryLocCount/${value}`).then(res => {
                    
                        if (parseInt(res.bean) > 0) {
                            callback()
                        } else {
                            this.inputData[rule.field] = ""
                            callback(new Error())
                        }
                }).catch(e => {
                  this.inputData[rule.field] = ""
                  callback(new Error())
                })
            } else {
                callback()
            }
        },
        interval(rule, value, callback) {
            if (value === '') {
                callback(new Error());
            } else {
                var re = /^[0-9]*$/;
                let te = value;
                let flag = re.test(te)
                if (flag) {
                    if (value < 0) {
                        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                        this.inputData[rule.field] = ""
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                    this.inputData[rule.field] = ""
                    callback(new Error());
                }
            }
        },
        setdata(data, id, close) {
            this.inputData.toloc = data.loc;
            close(false);
        }
    },
    mounted() {

    },
    components: {
        "v-detail": detail,
    },

}
</script>

<style scoped>

</style>
